import 'package:dartkit/dartkit.dart';
import 'package:test/test.dart';

/// 测试将各种类型json化
void main() {
  test("Primitive测试", () {
    expect(jsonfy(2), 2);
    expect(jsonfy(2.0), 2.0);
    expect(jsonfy("str"), "str");
    // jsonEncode会多加2个双引号
    expect(stringify("str"), "str");
    expect(jsonfy(true), true);
  });

  test("基础对象测试", () {
    final people = jsonfy(pseudoThree);
    expect(people, isMap);
    expect(people["name"], "张三");
  });

  test("Map各种类型嵌套测试", () {
    final map = {
      "rawable": pseudoThree,
      "int": 3,
      "list": [...pseudoPeople, 4],
    };
    expect(() => jsonfy(map), returnsNormally);
  });

  test("时间类型测试", () {
    final date = Date(2024, 01, 5);
    expect(stringify(date), date.toString());
    final time = DateTime.now();
    expect(stringify(time), time.toString());
  });

  test("错误测试", () {
    final exception = Exception("一个Exception");
    expect(stringify(exception), exception.toString());
    final bug = Bug("一个Bug");
    expect(stringify(bug), bug.toString());
  });
}
